//
//  DistrictDropView.m
//  小团购
//
//  Created by 樊荣海 on 15/1/23.
//  Copyright (c) 2015年 樊荣海. All rights reserved.
//

#import "DistrictDropView.h"

@interface DistrictDropView () {


    NSMutableArray *_btns;
}

@end

@implementation DistrictDropView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self == [super initWithFrame:frame]) {
        
        _btns = [NSMutableArray array];
        
       NSString *cityName = [[DBTool sharedDBTool] selectCurrentCity];
        
        CityModel *city = [[MetaDataTool sharedMetaDataTool] totalCities][cityName];
        
        // 1.当前城市的所有区域
        NSMutableArray *districts = [NSMutableArray array];
        // 1.1.全部商区
        DistrictModel *all = [[DistrictModel alloc] init];
        all.name = @"全部商区";
        [districts addObject:all];
        
        //1.2.其他商区
        [districts addObjectsFromArray:city.districts];

        for (int i = 0; i < districts.count; i++) {
            
            DistrictModel *model = districts[i];
            
            DisDropBtn *btn;
            if (i >= _btns.count) {
                btn = [[DisDropBtn alloc] initWithFrame:CGRectMake(DropScrollViewW*i, 0, 0, 0)];
                [_btns addObject:btn];
            } else {
                btn = _btns[i];
                
            }
            
            btn.dis = model;
            [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            [self.scrollView addSubview:btn];
            
//            if (i==0) {
//                btn.selected = YES;
//                self.currentBtn = btn;
//            }
            
        }
        
        for (NSInteger i = districts.count; i < _btns.count; i++) {
            DisDropBtn *btn = _btns[i];
            btn.hidden = YES;
        }
        
        self.scrollView.contentSize = CGSizeMake(DropScrollViewW*districts.count, DropScrollViewH);
    }
    
    return self;
    
}

@end
